package home.project;

/**
 * ...
 * @author an.vuongngocduy
 */
class Physic
{
	//horizotal and vertiacal position
	private var __px:Float;
	private var __py:Float;
	
	//horizontal and vertical velocity
	private var __vx:Float;
	private var __vy:Float;
	
	//horizotal and vertical acceleration
	private var __ax:Float;	
	private var __ay:Float;
	
	//should we respect the gravity in our calculation ?
	private var __gravityEnabled:Bool;
	
	public function new() 
	{
		__px = __py = 0;
		__vx = __vy = 0;
		__ax = __ay = 0;
		__gravityEnabled = true;
	}
	
	public function getPositionX():Float
	{
		return __px;
	}
	
	public function getPositionY():Float
	{
		return __py;
	}
	
	public function setVelocityX(p_vx:Float):Void
	{
		__vx = p_vx;
	}
	
	public function setVelocityY(p_vy:Float):Void
	{
		__vy = p_vy;
	}
	
	public function setVelocity(p_vx:Float, p_vy:Float):Void
	{
		__vx = p_vx;	__vy = p_vy;
	}
	
	public function setAccelerationX(p_ax:Float):Void
	{
		__ax = p_ax;
	}
	
	public function setAccelerationY(p_ay:Float):Void
	{
		__ay = p_ay;
	}
	
	public function setAcceleration(p_ax:Float, p_ay:Float):Void
	{
		__ax = p_ax;	__ay = p_ay;
	}
	
	public function enableGravity(p_enabled:Bool):Void
	{
		__gravityEnabled = p_enabled;
	}
	
	public function apply(p_delta:Float):Void
	{
		var grav:Float = 0;
		if (__gravityEnabled)
			grav = 1;
		__vx += __ax * (Globals.sElapsedTime / 1000.0);
		__vy += __ay * (Globals.sElapsedTime / 1000.0);
		__px += __vx * (Globals.sElapsedTime / 1000.0);
		__py += __vy * (Globals.sElapsedTime / 1000.0);
	}
}